package com.trial.eyefollowupapp

import androidx.compose.runtime.Composable
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.navArgument
import androidx.navigation.NavHostController
import com.trial.eyefollowupapp.screens.FollowUpScreen
import com.trial.eyefollowupapp.screens.HomeScreen
import com.trial.eyefollowupapp.screens.LoginScreen
import com.trial.eyefollowupapp.screens.RecordDetailScreen

@Composable
fun NavigationGraph(navController: NavHostController) {
    NavHost(navController, startDestination = "login") {

        composable("login") {
            LoginScreen(navController)
        }

        // 接收参数：userName
        composable(
            "home/{userName}",
            arguments = listOf(navArgument("userName") {
                type = NavType.StringType
                defaultValue = "用户"
            })
        ) { backStackEntry ->
            val userName = backStackEntry.arguments?.getString("userName") ?: "用户"
            HomeScreen(navController, userName)
        }

        composable("followUp/{userName}") { backStackEntry ->
            val userName = backStackEntry.arguments?.getString("userName") ?: ""
            FollowUpScreen(
                navController = navController,
                username = userName,
                onRecordClick = { recordId ->
                    navController.navigate("recordDetail/$recordId")
                }
            )
        }

        composable(
            "recordDetail/{recordId}",
            arguments = listOf(navArgument("recordId") {
                type = NavType.IntType
                defaultValue = 0
            })
        ) {
            val recordId = it.arguments?.getInt("recordId") ?: 0
            RecordDetailScreen(navController = navController, recordId = recordId)
        }
    }
}
